/*
 * ProgressBar.cpp
 *
 *  Created on: May 5, 2012
 *      Author: gonzalo
 */

#include "ProgressBar.h"
#include "../../common/utils/UtilString.h"

#define PROGRESSBAR_FONT_SIZE 6

ProgressBar::ProgressBar(int porcent, int posX, int posY, Widget* parent):
Widget(Color::AZUL,PROGRESS_BARRA_WIDTH,PROGRESS_BARRA_HEIGHT,posX,posY,parent){
	this->porcent = porcent;

	this->lblPorcent = new Label(UtilString::intToString(porcent),PROGRESSBAR_FONT_SIZE,parent,posX,posY);

	this->fillSurface = SurfaceUtils::colorSurface(PROGRESS_BARRA_WIDTH,PROGRESS_BARRA_HEIGHT,Color::VERDE);
}

void ProgressBar::showOn(SDL_Surface* surface) {

	SDL_Rect* fillRect = this->parcel->getRectangle();
	fillRect->w = fillSurface->w;
	fillRect->h = fillSurface->h;

	//Le pongo el porcentaje de vida al medio
	lblPorcent->showOn(this->fillSurface);

	Widget::showOn(surface);

	SDL_BlitSurface(this->fillSurface, NULL, surface, fillRect);


}


ProgressBar::~ProgressBar() {
	SDL_FreeSurface(fillSurface);
	delete lblPorcent;
}



